package com.hualan.zhsq.controller.car;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.entity.car.ParkingSpace;
import com.hualan.zhsq.service.car.ParkingSpaceService;
import com.hualan.zhsq.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName ParkingSpaceController
 * @Description TODO
 * @Author ZheRan
 * @Date 2025年08月05日 下午7:38
 * @Version 1.0
 */
@RestController
public class ParkingSpaceController {
    @Autowired
    private ParkingSpaceService parkingSpaceService;

    //插入一条数据
    @PostMapping("/parkingSpace/add")
    public Result add(@RequestBody ParkingSpace parkingSpace) {
        return Result.success(parkingSpaceService.add(parkingSpace));
    }

    //逻辑删除一条数据
    @DeleteMapping("/parkingSpace/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        return Result.success(parkingSpaceService.remove(id));
    }

    //批量逻辑删除数据
    @DeleteMapping("/parkingSpace/removeBatch")
    public Result removeBatch(Integer[] ids) {
        return Result.success(parkingSpaceService.removeBatch(ids));
    }

    //修改一条数据
    @PutMapping("/parkingSpace/edit")
    public Result edit(@RequestBody ParkingSpace parkingSpace) {
        return Result.success(parkingSpaceService.edit(parkingSpace));
    }

    //根据id查询数据
    @GetMapping("/parkingSpace/findById/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(parkingSpaceService.findById(id));
    }

    //查询所有数据
    @GetMapping("/parkingSpace/findPage")
    public Result findPage() {
        return Result.success(parkingSpaceService.findPage(1, 10, new ParkingSpace()));
    }

    /*
     *
     * @Description 分页多表联查
     * @param pageNum 页码
     * @param pageSize 每页条数
     * @param parkingSpace 查询条件
     */
    @GetMapping("/parkingSpace/findPageByResident")
    public Result<Map<String,Object>> findPageByResident(Integer pageNum, Integer pageSize, ParkingSpace parkingSpace) {
        return Result.success(parkingSpaceService.parkingSpaceResident( pageNum, pageSize, parkingSpace));
    }

}
